<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
 <!DOCTYPE html>
<html>

<head>
	<base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>关键词列表</title>
    <meta name="keywords" content="关键词列表">
    <meta name="description" content="关键词列表">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="static/templet/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/templet/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="static/templet/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="static/templet/css/animate.min.css" rel="stylesheet">
    <!-- Data Tables -->
    <link href="static/templet/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="static/templet/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    	<form method="post" id="keyWordForm" action="keyWordGE/list">
        <div class="row">    
        <!-- 检索 -->
        	<div class="col-sm-12">
        		<div class="ibox float-e-margins">
                    <div class="ibox-content">
                    <table class="table">
                    <thead>
        			<tr>
        				<td >
        					<div class="input-group">
        						 <input type="hidden" class="form-control" onkeydown="onKeyDown(event)" name="userId" id="userId" value="${pam.userId}"/>
							     <input type="text" class="form-control" onkeydown="onKeyDown(event)" name="keyWord" id="keyWord" value="${pam.keyWord}" placeholder="请输入关键字"/>
							</div>
        				</td>
        				<td >
        					<div class="input-group">
							     <input type="text" class="form-control" onkeydown="onKeyDown(event)" name="domain" id="domain" value="${pam.domain}" placeholder="请输入域名"/>
							</div>
        				</td>
        				<td >
        					<select class="form-control" name="typeValue" id="typeValue" data-placeholder="搜索引擎" style="vertical-align:top;width:150px;">
					            <option value="">搜索引擎</option>
					            <c:forEach items="${engineList}" var="engin">
					            	<option value="${engin.code }" <c:if test="${pam.typeValue == engin.code}">selected</c:if>>${engin.name  }</option>
					            </c:forEach>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="state" id="state" data-placeholder="关键字状态" style="vertical-align:top;width: 150px;">
					            <option value="">关键字状态</option>
					            <option value="01" <c:if test="${pam.state == '01'}">selected</c:if>>使用中</option>
					            <option value="02" <c:if test="${pam.state == '02'}">selected</c:if>>已停用</option>
					        </select>
					        <input type="hidden" name="orderBy" id="orderBy" value="${pam.orderBy}">
					        <input type="hidden" name="desc" id="desc" value="${pam.desc}">
        				</td>
        				<!-- 
        				<td >
        					<select class="form-control" name="orderBy" id="orderBy" data-placeholder="排序方式" style="vertical-align:top;width: 150px;">
					            <option value="">排序方式</option>
					            <option value="createTime" <c:if test="${pam.orderBy == 'createTime'}">selected</c:if>>添加日期</option>
					            <option value="comDay" <c:if test="${pam.orderBy == 'comDay'}">selected</c:if>>达标天数</option>
					            <option value="newRanking" <c:if test="${pam.orderBy == 'newRanking'}">selected</c:if>>最新排名</option>
					            <option value="price" <c:if test="${pam.orderBy == 'price'}">selected</c:if>>价格</option>
					        </select>
        				</td>
        				 -->
        				<td >
        					<select class="form-control" name="isTarget" id="isTarget" data-placeholder="达标情况" style="vertical-align:top;width: 150px;">
					            <option value="">达标情况</option>
					            <option value="03" <c:if test="${pam.isTarget == '03'}">selected</c:if>>今日达标</option>
					            <option value="00" <c:if test="${pam.isTarget == '00'}">selected</c:if>>未达标</option>
					            <option value="01" <c:if test="${pam.isTarget == '01'}">selected</c:if>>已达标</option>
					        </select>
        				</td> 
        				<td >
        					<select class="form-control" name="rankingInterval" id="rankingInterval" data-placeholder="排名区间" style="vertical-align:top;">
					            <option value="">排名区间</option>
					            <option value="1" <c:if test="${pam.rankingInterval == '1'}">selected</c:if>>1-10</option>
					            <option value="2" <c:if test="${pam.rankingInterval == '2'}">selected</c:if>>11-50</option>
					            <option value="3" <c:if test="${pam.rankingInterval == '3'}">selected</c:if>>51-100</option>
					            <option value="4" <c:if test="${pam.rankingInterval == '4'}">selected</c:if>>100+</option>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="groupId" id="groupId" data-placeholder="分组" style="vertical-align:top;width: 150px;">
					            <option value="">分组</option>
					            <c:forEach items="${groupList}" var="group">
					            	<option value="${group.id }" >${group.name }</option>
					            </c:forEach>
					        </select>
        				</td>
        				<td style="width:1%;">
        					<span style="float:right;"><input type="button" class="btn btn-primary" onclick="searchs();" value="检索"/></span>
        				</td>
        				<td style="width:1%;">
        					<span style="float:right;"><input type="button" class="btn btn-primary" onclick="exportKeyword();" value="导出"/></span>
        				</td>
        			</tr>
        		</table>
                        <table class="table-bordered table table-hover dataTable" id="keyWordTable">
                            <thead>
                                <tr>
                                	<th class="text-center"><input type="checkbox" id="checked_all" onclick="checkOrCancelAll();"/>&nbsp;&nbsp;&nbsp;&nbsp;<span id="choose">全选</span></th>
                                    <th class="text-center">id</th>
                                    <th class="text-center">用户名</th>
                                    <th class="text-center">关键词</th>
                                    <th class="text-center">类型</th>
                                    <th class="text-center">域名</th>
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'keywordIndex' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="keywordIndex">指数</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'keywordIndex' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="keywordIndex">指数</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="keywordIndex">指数</th>
                                    </c:otherwise>
                                    </c:choose>
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'price' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="price">单价</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'price' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="price">单价</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="price">单价</th>
                                    </c:otherwise>
                                    </c:choose>
                                    <th class="text-center">目标排名</th>
                                    <th class="text-center">扣费详情</th>
                                    <th class="text-center">状态</th>
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'updateTime' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="updateTime">更新日期</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'updateTime' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="updateTime">更新日期</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="updateTime">更新日期</th>
                                    </c:otherwise>
                                    </c:choose>
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'useDay' && pam.desc == 'asc'}">
                                    <th class="sorting_desc" data-id="useDay">使用天数</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'useDay' && pam.desc == 'desc'}">
                                    <th class="sorting_asc" data-id="useDay">使用天数</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="useDay">使用天数</th>
                                    </c:otherwise>
                                    </c:choose>
                                    
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'consumeDays' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="consumeDays">消费天数</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'consumeDays' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="consumeDays">消费天数</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="consumeDays">消费天数</th>
                                    </c:otherwise>
                                    </c:choose>
                                    
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'initRanking' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="initRanking">初始排名</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'initRanking' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="initRanking">初始排名</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="initRanking">初始排名</th>
                                    </c:otherwise>
                                    </c:choose>
                                    
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'ydayRanking' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="ydayRanking">昨日排名</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'ydayRanking' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="ydayRanking">昨日排名</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="ydayRanking">昨日排名</th>
                                    </c:otherwise>
                                    </c:choose>
                                    
                                    <c:choose>
                                    <c:when test="${pam.orderBy == 'newRanking' && pam.desc == 'asc'}">
                                    <th class="sorting_asc" data-id="newRanking">最新排名</th>
                                    </c:when>
                                    <c:when test="${pam.orderBy == 'newRanking' && pam.desc == 'desc'}">
                                    <th class="sorting_desc" data-id="newRanking">最新排名</th>
                                    </c:when>
                                    <c:otherwise>
                                    <th class="sorting" data-id="newRanking">最新排名</th>
                                    </c:otherwise>
                                    </c:choose>
                                    
                                    <th class="text-center">达标状态</th>
                                    <th class="text-center">组名</th>
                                    <!-- <th class="text-center">用户欠费状态</th>-->
                                    <th class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
							<c:forEach items="${page.list}" var="key" varStatus="vs">
                            	<tr class="text-center">
                            		<td><input type="checkbox" class="checked_pro" name="checkbox"  value="${key.childId }"/></td>
                                    <td>${key.id }</td>
									<td>${key.userName }</td>
									<td><a href="${key.engineUrl }${key.keyWordName }" target="_blank" title="详情">${key.keyWordName }</a></td>
									<td>${key.typeValue }</td>
									<td>${key.domain }</td>
									<td>
										<c:choose>
											<c:when test="${key.keywordIndex == '-1'}">
												0
											</c:when>
											<c:otherwise>
												${key.keywordIndex }
											</c:otherwise>
										</c:choose>
									</td>
									<td>${key.price }</td>
									<td>${key.targetRanking }</td>
									<td> <a  href="javascript:billingDetails('${key.keyWordName }','${key.engine_code }','${key.domain }');" title="详情">详情</a></td>
									<td>
										<c:if test="${key.state == '00'}">
											待审核
										</c:if>
										<c:if test="${key.state == '01'}">
											使用中
										</c:if>
										<c:if test="${key.state == '02'}">
											已停用
										</c:if>
										<c:if test="${key.state == '03'}">
											禁用
										</c:if>
									</td>
									<td>
										<fmt:parseDate value="${key.createTime }" pattern="yyyy-MM-dd" var="utime"/> 
										<fmt:formatDate value="${utime}" pattern="yyyy-MM-dd"/>
									</td>
									<td>${key.useDay }</td>
									<td>${key.consumeDays }</td>
									<td>
										<c:choose>
											<c:when test="${key.initRanking == '-1'}">
												-
											</c:when>
											<c:when test="${key.initRanking >= '10000'}">
												100+
											</c:when>
											<c:otherwise>
												${key.initRanking }
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${key.ydayRanking == '-1'}">
												-
											</c:when>
											<c:when test="${key.ydayRanking >= '10000'}">
												100+
											</c:when>
											<c:otherwise>
												${key.ydayRanking }
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${key.newRanking == '-1'}">
												-
											</c:when>
											<c:when test="${key.newRanking >= '10000'}">
												100+
											</c:when>
											<c:otherwise>
											<span class="text-danger" >${key.newRanking }</span>
												
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:if test="${key.isTarget == '00'}">
											未达标
										</c:if>
										<c:if test="${key.isTarget == '01'}">
											已达标
										</c:if>
									</td>
									<td>${key.groupName }</td>
									<!-- 
									<td>
										<c:if test="${key.serviceState == '00'}">
											服务中
										</c:if>
										<c:if test="${key.serviceState == '01'}">
											欠费
										</c:if>
									</td>	
									-->
									<td>
	                                    <div class="btn-group">
		                                	<button data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span class="caret"></span>
		                                	</button>
			                                <ul class="dropdown-menu">
			                                    <li><a href="javascript:deleteKeyWords('${key.id }');" title="删除">删除</a>
			                                    </li>
			                                </ul>
	                            		</div>
                                    
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        <jsp:include page="/WEB-INF/jsp/page.jsp">
                        	<jsp:param value="keyWordForm" name="form"/>
                        </jsp:include>
	                    <div class="form-group form-inline">
        					<button type="button" class="btn btn-danger" onclick="bacthGroup()">批量分组</button>
        				</div>
				   	</div>
                </div>
            </div>
        </div>
        </form>
    </div>
    <script src="static/templet/js/jquery.min.js?v=2.1.4"></script>
    <script src="static/templet/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="static/templet/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="static/templet/js/plugins/layer/layer.min.js"></script>
    <script src="static/templet/js/iframe.min.js"></script>
    <script src="static/templet/js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript">
    
    function searchs(){
    	$("#keyWordForm").attr("action","keyWordGE/list")
    	$("#keyWordForm").submit();
    }

    $('.sorting,.sorting_asc,.sorting_desc').on('click', function(){
		$this = $(this);
		$classValue = $(this).attr('class');
		$dataId = $this.attr('data-id');
		if($classValue == 'sorting' || $classValue == 'sorting_desc'){
			$this.attr('class','sorting_asc');
			if($dataId == 'useDay'){
				$('#desc').val('desc');
			}else{
				$('#desc').val('asc');
			}
			
		}else{
			$this.attr('class','sorting_desc');
			if($dataId == 'useDay'){
				$('#desc').val('asc');
			}else{
				$('#desc').val('desc');
			}
		}
		$('#orderBy').val($dataId);
		
		searchs();
	})
    
    function billingDetails(name,typeValue,domain){
    	parent.layer.open({
    	    type: 2,
    	    title: '账单',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['80%', '70%'],
    	    content: 'bill/keyWordDeduc?keyWord='+ name + '&engine_code=' + typeValue + '&domain=' +domain,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    //全选 全不选
    //页面加载的时候,所有的复选框都是未选中的状态
	function checkOrCancelAll(){
		//1.获取checkbo的元素对象
		var chElt=document.getElementById("checked_all");
		//2.获取选中状态
		var checkedElt=chElt.checked;
		//3.若checked=true,将所有的复选框选中,checked=false,将所有的复选框取消
		var allCheck=document.getElementsByName("checkbox");
		//4.循环遍历取出每一个复选框中的元素
		var mySpan=document.getElementById("choose");
		if(checkedElt){
			//全选
			for(var i=0;i<allCheck.length;i++){
				//设置复选框的选中状态
				allCheck[i].checked=true;
			}
			mySpan.innerHTML="取消全选";
		}else{
			//取消全选
			for(var i=0;i<allCheck.length;i++){
				allCheck[i].checked=false;
			}
			mySpan.innerHTML="全选";
		}
	}
    
  //批量分组
	function bacthGroup() {
	    //获取所有被选中的记录
	    var rows = document.getElementsByName("checkbox");
	    if (rows.length== 0) {
	        alert("请先选择要修改的记录!");
	        return;
	    }
	    var ids = '';
	    for (var i = 0; i < rows.length; i++) {
	    	if(rows[i].checked){
	    		ids += rows[i].value + ",";
	    	}
	    }
	    ids = ids.substring(0, ids.length - 1);
	    editGroup(ids);
	}
	
	//分组
	function editGroup(ids){
    	parent.layer.open({
    	    type: 2,
    	    title: '分组',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '30%'],
    	    content: 'keyWordG/editGroupPage?ids='+ids,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }

	//批量修改
	function editPriceList() {
		//获取所有被选中的记录
	    var rows = document.getElementsByName("checkbox");
	    if (rows.length== 0) {
	        alert("请先选择要修改的记录!");
	        return;
	    }
	    var ids = '';
	    for (var i = 0; i < rows.length; i++) {
	    	if(rows[i].checked){
	    		ids += rows[i].value + ",";
	    	}
	    }
	    ids = ids.substring(0, ids.length - 1);
	    editBatchPrice(ids);
	}
	
	//批量修改价格
	function editBatchPrice(ids){
    	parent.layer.open({
    	    type: 2,
    	    title: '关键字',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '40%'],
    	    content: 'keyWordG/editPricePage?ids='+ids,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
	function deleteKeyWords(ids){
		layer.confirm('确认要删除所选关键词吗？',function(index){
			$.ajax({
				type: 'get',
				url: 'keyWordGE/delete',
				data: {ids : ids},
				success: function(data){
					var result = data.result;
					var state = result.state;
					if(state == 1){
						layer.msg(result.message, {icon: 1});
						location.reload();
					}else{
						layer.msg(result.message, {icon: 1});
					}
				},
				error:function(data) {
					layer.msg("删除失败", {icon: 1});
				},
			});		
		});
	}
	
	//导出
    function exportKeyword(){
    	var load = layer.load(1, {
	        shade: [0.1,'#fff']
	    });
		/* if(document.getElementById("state").value != '01'){
			layer.alert('您导出的关键词不是使用中', {icon: 1});
			layer.close(load);
			return;
		} */
		$("#keyWordForm").attr("action","keyWordGE/export")
    	$("#keyWordForm").submit();
		layer.close(load);
    }
    </script>

</body>

</html>